package com.fin.zw.intelligentbot.controller;

import com.fin.zw.intelligentbot.annotation.CurrentUser;
import com.fin.zw.intelligentbot.entity.BaseEntity;
import com.fin.zw.intelligentbot.entity.CategoryLabel;
import com.fin.zw.intelligentbot.model.session.SessionModel;
import com.fin.zw.intelligentbot.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


@RestController
@RequestMapping("/ai/category")
@Api(value = "客户分类标签",description = "客户分类标签")
public class CategoryLabelController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/fetchPage")
    @ApiOperation(value = "客户分类查询",notes = "客户分类查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<BaseEntity>> queryAiAccountAll(Pageable pageable,
                                                              CategoryLabel condition,
                                                              @ApiIgnore @CurrentUser SessionModel sessionModel){

        Page<BaseEntity> page = this.categoryService.fetchPage(sessionModel, condition, pageable);
        return ResponseEntity.ok().body(page);
    }


    @GetMapping("/fetch")
    @ApiOperation(value = "客户分类查询", notes = "客户分类查询")
    public ResponseEntity<List<BaseEntity>> getAiAccountList(@ApiIgnore @CurrentUser SessionModel sessionModel,
                                                             CategoryLabel condition){
        List<BaseEntity> list = this.categoryService.fetch(sessionModel,condition);
        return ResponseEntity.ok().body(list);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加分类标签",notes = "添加分类标签")
    public ResponseEntity<String> add(@RequestBody CategoryLabel category,
                                                @ApiIgnore @CurrentUser SessionModel sessionModel){
        this.categoryService.add(category,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }

    @RequestMapping(value = "/update",method = {RequestMethod.PUT,RequestMethod.PATCH})
    @ApiOperation(value = "更新分类标签",notes = "更新分类标签")
    public ResponseEntity<String> updateCircuit(@RequestBody CategoryLabel category,
                                                @ApiIgnore @CurrentUser SessionModel sessionModel){
        this.categoryService.update(category,sessionModel);
        return ResponseEntity.ok().body("操作成功");
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "客户分类标签",notes = "客户分类标签")
    public ResponseEntity<String> delete(@PathVariable String id){
        this.categoryService.delete(id);
        return ResponseEntity.ok().body("操作成功");
    }
}
